package org.i77soft.games.MineSweeperAcer;

/*
import and.awt.Color;
import and.awt.Graphics;
//import and.awt.geom.BufferedImage;
import net.pbdavey.awt.AwtView;
import net.pbdavey.awt.Font;
import net.pbdavey.awt.FontMetrics;
import net.pbdavey.awt.Graphics2D;
//import java.awt.Graphics2D;
//import and.awt.Graphics2D;
import net.pbdavey.awt.RenderingHints;
import and.awt.BasicStroke;
import and.awt.Color;
import and.awt.Dimension;
import and.awt.geom.Arc2D;
import and.awt.geom.Ellipse2D;
import and.awt.geom.GeneralPath;
import and.awt.geom.Line2D;
import and.awt.geom.Rectangle2D;
import and.awt.geom.RoundRectangle2D;
import android.content.Context;
import android.util.AttributeSet;
//*/

import java.awt.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.net.URL;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import com.sun.image.codec.jpeg.JPEGImageDecoder;

public abstract class gameState {
    protected static BufferedImage backbuffer;
    protected static Graphics2D g;
    protected BufferedImage background;
    public abstract void update(long l);
    public abstract void render();
    public abstract void onActivate();

    public void drawText(String s, int i, int j) {
        g.setColor(Color.WHITE);
        g.drawString(s, i, j);
    }

    public gameState() {
        backbuffer = new BufferedImage(400, 500, 1);
        g = backbuffer.createGraphics();
    }

    private URL getURL(String s) {
        URL url = null;
        url = getClass().getResource(s);
        return url;
    }

    public void loadBackgroundImage(String s) {
        JPEGImageDecoder decoder = null;
        byte[] imgBytes = null;        
        try {
            //background = ImageIO.read(getURL(s));
            Bitmap bmp = BitmapFactory.decodeFile(getURL(s).toString());
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            bmp.compress(Bitmap.CompressFormat.JPEG, 100, bout);
            imgBytes = bout.toByteArray();
            ByteArrayInputStream bin = new ByteArrayInputStream(imgBytes);
            decoder = JPEGCodec.createJPEGDecoder(bin);
            background = decoder.decodeAsBufferedImage();
            bout.close();
            bin.close();
        } catch (Exception exception) {
            System.out.print((new StringBuilder()).append(
                    "Could not load file ").append(s).toString());
        }
    }

    public BufferedImage loadImage(String s) {
        BufferedImage bufferedimage = null;
        JPEGImageDecoder decoder = null;
        byte[] imgBytes = null;
        try {
            //bufferedimage = ImageIO.read(getURL(s));
            Bitmap bmp = BitmapFactory.decodeFile(getURL(s).toString());
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            bmp.compress(Bitmap.CompressFormat.JPEG, 100, bout);
            imgBytes = bout.toByteArray();
            ByteArrayInputStream bin = new ByteArrayInputStream(imgBytes);
            decoder = JPEGCodec.createJPEGDecoder(bin);
            bufferedimage = decoder.decodeAsBufferedImage();
            bout.close();
            bin.close();            
        } catch (Exception exception) {
            System.out.print((new StringBuilder()).append(
                    "Could not load file ").append(s).toString());
        }
        return bufferedimage;
    }

    public void flip(Graphics g1) {
        g1.drawImage(backbuffer, 0, 0, null);
    }
}
